<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据字典管理维护界面</title>

    <script src="../../res/js/base.js"></script>
    <script src="../../res/js/jquery-3.4.1.min.js"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css">


    <style type="text/css">
        #main {
            margin: 10px;
        }

        .layui-input-block{
            width:60%;
            margin-left: 148px;

        }

        .layui-form-label{
            width:100px;
            text-align: center;
        }



        body{
            padding-top:5px;
        }
    </style>

    <script type="text/javascript">

    </script>


</head>
<body>



<form class="layui-form" action="" id="AtsDataDicForm">
    <input type="hidden" name="did" id="did"/>
    <div class="layui-form-item">
        <label class="layui-form-label">字典编码</label>
        <div class="layui-input-block">
            <input type="text" name="dcode" id="dcode"   lay-verify="required" placeholder="请输入字典编码" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">字典类型</label>
        <div class="layui-input-block">
            <input type="text" name="dname" id="dname" required  lay-verify="required" placeholder="请输入字典名称" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
    <label class="layui-form-label">字典名称</label>
    <div class="layui-input-block">
        <input type="text" name="dtype" id="dtype" required  lay-verify="required" placeholder="请输入字典名称" autocomplete="off" class="layui-input">
    </div>
</div>

    <div id="bscjDiv">
        <div id="tableDiv">
            <table id="demo" lay-filter="test"></table>
        </div>
    </div>

    <div class="layui-form-item" id="buttonDiv">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>


</form>

<script>
    $(function(){
        var did = getQueryString("did");

        if(did!=null){
       // var url = "../atsDataDicController/selectByPrimaryKey";
        var  url= getRootPath() + 'atsDataDicController/selectByPrimaryKey'; //数据接口

            var data = {did:did};
            $.post(url,data,function(obj){
                $("#did").val(obj.did);
                $("#dcode").val(obj.dcode);
                $("#dname").val(obj.dname);
                $("#dtype").val(obj.dtype);
            });
        }


    })


    var form = null ;

    layui.use('form', function(){
        form = layui.form;
        var laydate = layui.laydate;

        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));


            var formData = new FormData(document.getElementById("AtsDataDicForm"));

            //var url = "../atsDataDicController/saveOrUpdate";
            var  url= getRootPath() + 'atsDataDicController/saveOrUpdate'; //数据接口


            $.ajax({
                url:url,
                type:"post",
                data:formData,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    if(obj.num==1){

                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            //关闭当前层//当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            parent.table2.reload();
                        });

                    }
                },
                error:function(e){
                    layer.msg("操作错误!");
                }



            });

            return false;

        });

    });

    //修改页面的赋值
    function findById(){

        var id = getQueryString("did");
        if(!id){
            return ;
        }
        console.info(id);
        //var url = "../atsDataDicController/selectByPrimaryKey";
        var  url= getRootPath() + 'atsDataDicController/selectByPrimaryKey'; //数据接口
        var data = {id:id};
        $.post(url,data,function(obj){
            $("#did").val(obj.did);

            $("#dcode").val(obj.dcode);
            $("#dname").val(obj.dname);
            $("#dtype").val(obj.dtype);

            //重新渲染
            form.render();

        });
    }



</script>

</body>
</html>